from time import sleep

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

jw_capabilities = {
    'platformName': 'Android',
    'platformVersion': '9',
    'deviceName':'127.0.0.1:10027',
    'app':'/home/appium/apps/kaoyan3.1.0.apk',
    'appPackage':'com.tal.kaoyan',
    'appActivity':'com.tal.kaoyan.ui.activity.SplashActivity',
    'noReset':False
}
# 防止乱码
jw_capabilities['unicodekeyboard'] = True
jw_capabilities['resetkeyboard'] = True
jwdriver = webdriver.Remote("http://localhost:4723/wd/hub",jw_capabilities)
sleep(2)
# 取消 android:id/button2
try:
    cancelBtn = jwdriver.find_element(AppiumBy.ID,'android:id/button2')
except:
    print('没有找到取消按钮')
else:
    print('找到取消按钮')
    cancelBtn.click()
sleep(2)

# 算出屏幕宽、高
size = jwdriver.get_window_size()
print(size)
width = size['width']
height = size['height']
#左划相对坐标
x1 = width*0.9
y1 = height*0.5
x2 = width*0.1
y2 = y1
# 交给swipe运行
for i in range(2):
    jwdriver.swipe(x1,y1,x2,y2,2000)
    sleep(3)